# -*- coding: utf-8 -*-
import cv2 as cv
from mediapipe.python.solutions import drawing_utils, face_detection

cap = cv.VideoCapture("videos/face2.mp4")

mpFaceDetection = face_detection.FaceDetection(min_detection_confidence=0.5)
mpDrawspec = drawing_utils.DrawingSpec(thickness=1, circle_radius=1)

while True:
    flag, frame = cap.read()

    frameRGB = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
    results = mpFaceDetection.process(frameRGB)

    if not results.detections:
        continue

    for detection in results.detections:
        # drawing_utils.draw_detection(frame, detection)
        drawing_utils.draw_detection(frame, detection, mpDrawspec, mpDrawspec)
        
        # x和y在[0.0, 1.0]范围内，通过图像的宽度和高度进行归一化
        print(detection)

    cv.imshow("video", frame)
    if cv.waitKey(0) & 0xFF == ord('q'):
        break

cap.release()
cv.destroyAllWindows()